$(document).ready(function() {	
	$("#frmImage").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {				
			pimage: {
				required	: true,
				validFormat	: true,
				validSize	: true
			}
		},
		messages: {	
			pimage: {
				required	: image_required,
				validFormat	: image_format,
				validSize	: image_size				
			}
		},
		errorPlacement: function(label, element) {				
			var id = element.attr('id');
			label.insertAfter($('#' + id));			
		},
		submitHandler: function(form) {
			var strToken 	= $('#ptoken').val();	
			var intPlaceId	= $('#pplaceid').val();		
			var strNote		= encodeURIComponent($('#pnote').val());							
			$.ajaxFileUpload ({
				url:			HOST_VFRIEND + 'ajax/placeup?token='+strToken+'&placeid='+intPlaceId+'&note='+strNote,
				secureuri:		false,
				fileElementId:	'pimage',
				dataType: 		'json',
				data:{
					name:'logan', 
					id:'id'
				},
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						closeUI();
						var strMsg = data.msg;
						showUIMessage(strMsg);						
						if(data.error == 0) {
							$.getJSON(				
								HOST_VFRIEND + 'ajax/placeimg?type=1&placeid='+intPlaceId+'&callback=?',		
								function(response) {					
									$('.boxDetail td.img').html(response['dfull']);	
									$('.boxDetail td.slideshow').html(response['dhtml']);							
								}
							);
						}
					}
				},
				error: function (data, status, e)
				{		
					closeUI();				
					alert(image_error);
				}
			});
		}
	});	
	$.validator.addMethod('validFormat', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return false;
		}
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validSize', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return false;
		}
		return validateImgSize("pimage");
	});	
});

